/*
 * Jamus
 * Copyright (C) 2010 Jamus Team
 *
 * Jamus is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Jamus is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Jamus.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * QFunctionAdaptor.h
 *
 *  Created on: Feb 3, 2010
 *      Author: christian moellinger
 */

#ifndef QPLAYERADAPTOR_H_
#define QPLAYERADAPTOR_H_

#include <QtDBus>
#include <iostream>
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
#include <log4cxx/logger.h>
#include "QFunctionWrapper.h"

using namespace std;

struct DBusStatus
{
    int Play; //Playing = 0, Paused = 1, Stopped = 2
    int Random; //Linearly = 0, Randomly = 1
    int Repeat; //Go_To_Next = 0, Repeat_Current = 1
    int RepeatPlaylist; //Stop_When_Finished = 0, Never_Give_Up_Playing = 1
};

Q_DECLARE_METATYPE( DBusStatus )

// Marshall the DBusStatus data into a D-BUS argument
QDBusArgument &operator << ( QDBusArgument &argument, const DBusStatus &status );
// Retrieve the DBusStatus data from the D-BUS argument
const QDBusArgument &operator >> ( const QDBusArgument &argument, DBusStatus &status );

class QPlayerAdaptor: public QDBusAbstractAdaptor
{
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "org.freedesktop.MediaPlayer")
private:
    QObject *parent;
    log4cxx::LoggerPtr logger;
    backend::Plugin &backend;
    boost::mutex mutex;

    int newState;
    int oldTrack;
    int currentTrack;
    int playState;
public:
    QPlayerAdaptor(QObject *parent);
    void onPlaybackStatusChanged();
    void emitSignals();
public slots:
	void Backward(int);
	void Forward(int);
	int GetCaps();
	DBusStatus GetStatus();
	QVariantMap GetMetadata();
	void LoadThemeFile(QString);
	void Mute();
	void Next();
	void Pause();
	void Play();
	void PlayPause();
	int PositionGet();
	void PositionSet(int);
	void Prev();
	void Repeat(bool);
	void ShowOSD();
	void Stop();
	void VolumeDown(int);
	int VolumeGet();
	void VolumeSet(int);
	void VolumeUp(int);
signals:
    void CapsChange(int);
    void StatusChange(DBusStatus);
    void TrackChange(QVariantMap);
};

#endif /* QPlayerADAPTOR_H_ */
